<?php
class news_detail extends database{
// add ------
	public function Add($id_news, $title, $content, $language, $status){				
		if(!$this->isInt($id_news)){
			return 3;
		}else if(!$this->isText($title)){
			return 4;
		}else if(!$this->isLen($title,0,200)){
			return 5;
		}else if(!$this->isText($content)){
			return 6;
		}else if(!$this->isInt($language)){
			return 7;
		}else if(!$this->isInt($status)){
			return 8;
		}else{			
			$sql="insert into news_detail(id_news, title, content, language, status) values(".$id_news.", '".$title."', '".$content."', ".$language.", ".$status.")";		
			if($result=$this->query($sql)){
				return 1;
			}else{
				return 0;
			}
		}
	}
// edit ------
	public function Edit($id, $id_news, $title, $content, $language, $status){				
		if(!$this->isInt($id)){
			return 2;
		}else if(!$this->isInt($id_news)){
			return 3;
		}else if(!$this->isText($title)){
			return 4;
		}else if(!$this->isLen($title,0,200)){
			return 5;
		}else if(!$this->isText($content)){
			return 6;
		}else if(!$this->isInt($language)){
			return 7;
		}else if(!$this->isInt($status)){
			return 8;
		}else{			
			$sql="update news_detail set id_news=".$id_news.", title='".$title."', content='".$content."', language=".$language.", status=".$status." where id=".$id."";		
			if($result=$this->query($sql)){
				return 1;
			}else{
				return 0;
			}
		}
	}
// Del ------
	public function Del($id){				
		if(!$this->isInt($id)){
			return 2;
		}else{			
			$sql="delete from news_detail where id=".$id."";		
			if($result=$this->query($sql)){
				return 1;
			}else{
				return 0;
			}
		}
	}
// del theo news
	public function DelIdNews($id){				
		if(!$this->isInt($id)){
			return 2;
		}else{			
			$sql="delete from news where id_news=".$id."";		
			if($result=$this->query($sql)){
				return 1;
			}else{
				return 0;
			}
		}
	}
// get by id
	public function GetById($id){	
		if(!$this->isInt($id)){
			return 2;
		}else{	
			$sql="select id, id_news, title, content, language, status from news_detail where id=".$id."";
			if($result=$this->query($sql)){
				if($this->CountRow($result)>0){
					while(($a=$this->fetch($result))!=NULL){
						$ds_sp[]=$this->unvalid($a); 
					}
					return $ds_sp;		
				}else{
					return 1;
				}
			}
		}
		return 0;
	}
// get all
	public function GetByIdNews($Top=0, $Position=0, $id_news, $language=-1, $status=10){	
		if(!$this->isInt($Top) || !$this->isInt($Position) ){
			return 2;	
		}else if(!$this->isInt($id_news)){
			return 3;
		}else if(!$this->isNum($language)){
			return 4;
		}else if(!$this->isInt($status)){
			return 5;
		}else{	
			if($status==10){
				$status	= "status<>2";	
			}else{
				$status	= " status=".$status;	
			}
			if($language==-1){
				$language	= "";	
			}else{
				$language	= " and language=".$language;	
			}
			if($Top>0){
				$Top=" limit ".$Position.", ".$Top." ";
			}else{
				$Top="";
			}
			$sql="select id, id_news, title, content, language, status from news_detail where id_news=".$id_news." and ".$status." ".$language.$Top;
			if($result=$this->query($sql)){
				if($this->CountRow($result)>0){
					while(($a=$this->fetch($result))!=NULL){
						$ds_sp[]=$this->unvalid($a); 
					}
					return $ds_sp;		
				}else{
					return 1;
				}
			}
		}
		return 0;
	}
// get all
	public function GetByAll($Top=0, $Position=0, $status=10){	
		if(!$this->isInt($Top) || !$this->isInt($Position) ){
			return 2;	
		}else if(!$this->isInt($status)){
			return 3;
		}else{	
			if($status==10){
				$status	= "status<>2";	
			}else{
				$status	= " status=".$status;	
			}
			if($Top>0){
				$Top=" limit ".$Position.", ".$Top." ";
			}else{
				$Top="";
			}
			$sql="select id, id_news, title, content, language, status from news_detail where ".$status." ".$Top;
			if($result=$this->query($sql)){
				if($this->CountRow($result)>0){
					while(($a=$this->fetch($result))!=NULL){
						$ds_sp[]=$this->unvalid($a); 
					}
					return $ds_sp;		
				}else{
					return 1;
				}
			}
		}
		return 0;
	}
}
?>